package org.ali.structuralpattern.filterpattern;

import org.ali.structuralpattern.filterpattern.filter.FilterCircular;
import org.ali.structuralpattern.filterpattern.filter.FilterCircularAndRed;
import org.ali.structuralpattern.filterpattern.filter.FilterRed;

import java.util.ArrayList;
import java.util.List;

/**
 * 过滤器模式
 */
public class Main {
    public static void main(String[] args) {
        List<Graph> graphs = new ArrayList<>() {{
            add(new Graph("Circular", "Red"));
            add(new Graph("Circular", "Green"));
            add(new Graph("Rectangle", "Red"));
            add(new Graph("Rectangle", "green"));
        }};

        FilterCircular filterCircular = new FilterCircular();
        FilterRed filterRed = new FilterRed();
        FilterCircularAndRed filterCircularAndRed = new FilterCircularAndRed(filterCircular, filterRed);

        System.out.println("Circular：");
        printGraphs(filterCircular.filter(graphs));
        System.out.println("Red：");
        printGraphs(filterRed.filter(graphs));
        System.out.println("CircularAndRed：");
        printGraphs(filterCircularAndRed.filter(graphs));
    }

    public static void printGraphs(List<Graph> graphs) {
        for (Graph graph : graphs) {
            System.out.println("Graph:[Shape：" + graph.getShape() + ", Color：" + graph.getColor() + "]");
        }
    }
}
